<template>
  <div class></div>
</template>
<script>
import axios from "@/utils/requestzz";

export default {
  name: "baseapi",
  components: {},
  data() {
    return {};
  },
  computed: {
    ishistory: function() {
      return this.$store.state.daping.ishistorytime;
    },
    timerangarr: function() {
      return this.$store.state.daping.timepick;
    }
  },
  watch: {
    
  },
  mounted() {},
  methods: {
    watchEvent() {
      //先清除定时任务
      if (
        this.$store.state.daping.intervalArr["APIqueryDbHeatplant"] != undefined
      ) {
        return;
      }
      console.log(this.$store.state.daping.bigScreen);
      let n_tmp = this.$store.state.daping.bigScreen;
      let g_bigscreen_data_arr = n_tmp.filter(item => {
        if (item.attrName == "heatplant_pids") {
          return true;
        }
      });
      this.loadData(g_bigscreen_data_arr[0].attrValue);
      let interval = setInterval(() => {
        let n_tmp = this.$store.state.daping.bigScreen;
        let g_bigscreen_data_arr = n_tmp.filter(item => {
          if (item.attrName == "heatplant_pids") {
            return true;
          }
        });
        this.loadData(g_bigscreen_data_arr[0].attrValue);
      }, this.$root.setting.data.interval);
      this.$store.state.daping.intervalArr["APIqueryDbHeatplant"] = [
        { interval: interval }
      ];
    },
    loadData(pidStr) {
      var hpObjArr = [];
      var hpPidArr = [];
      var pidStrArr = pidStr.split(","); //【2019年12月2日】在大屏配置页面勾选的热源 并且按照顺序传输过来
      for (var i = 0; i < pidStrArr.length; i++) {
        // var type = pidStrArr[i].split("@@")[0];
        var pid = pidStrArr[i].split("@@")[1];
        var name = pidStrArr[i].split("@@")[2];
        hpPidArr.push(pid);
        hpObjArr.push({
          pid: pid,
          name: name
        });
      }

      let queryJson = {
        queries: [
          {
            metric: "pid,m_001t,m_002t,m_001p,m_002p,m_001q,m_003qc",
            schema: "monitor"
          }
        ],
        table: "heatplant",
        search: "pid=" + hpPidArr.toString(),
        type: "lastest"
      }

      if (this.ishistory == "历史") {
        queryJson = {
          queries: [
            {
              metric: "pid,m_001t,m_002t,m_001p,m_002p,m_001q,m_003qc",
              schema: "monitor"
            }
          ],
          table: "heatplant",
          search: "pid=" + hpPidArr.toString(),
          type: "history",
          startTime: this.timerangarr[0].getTime(),
          endTime: this.timerangarr[1].getTime()
        };
      }

      axios.post("/open/queryDb", queryJson).then(res => {
        if (res.data["200"]) {
          //如果有则获取200中的结果
          var data200 = res.data["200"];
          this.$store.state.daping.queryDbHeatplant = data200;
          this.$store.state.daping.reyuantable = data200;
        }
      });
    }
  }
};
</script>
<style lang='scss' scoped>
</style>